﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using BusinessLogic.BusinessRules;
using BusinessLogic.ClassFactory;
using DataAccess;
using Model;
using EncryptUtily;

namespace RichECMS.ServerPages.User
{
    public partial class UpdatePsw : Util.BasePage.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { }
        }

        protected void ibtnSave_Click(object sender, ImageClickEventArgs e)
        {
            using (UserManageInfoFactory objFactory = new UserManageInfoFactory())
            {
                UserManageInfo objUserManageInfo = objFactory.Creator(State.LoginUser.UserID);
                if (EncryptUtily.EncryptUtily.LoginDecrypt(objUserManageInfo.DataItem.chvLoginPsw) == txtOldPsw.Text.Trim())
                {
                    if (txtPswOne.Text.Trim() == txtPswTwo.Text.Trim())
                    {
                        objUserManageInfo.DataItem.chvLoginPsw = EncryptUtily.EncryptUtily.LoginEncrypt(txtPswTwo.Text.Trim());
                        objUserManageInfo.Update();
                        Alert("密码修改成功！");
                        txtOldPsw.Text = string.Empty;
                        txtPswOne.Text = string.Empty;
                        txtPswTwo.Text = string.Empty;
                    }
                    else
                    {
                        Alert("新密码两次输入错误！");
                        txtPswOne.Text = string.Empty;
                        txtPswTwo.Text = string.Empty;
                    }
                }
                else
                {
                    Alert("旧密码输入错误，请重新输入！");
                    txtOldPsw.Text = string.Empty;
                }
            }
        }

        protected void ibtnReset_Click(object sender, ImageClickEventArgs e)
        {
            txtOldPsw.Text = string.Empty;
            txtPswOne.Text = string.Empty;
            txtPswTwo.Text = string.Empty;
        }
    }
}